//
//  MineTableViewCell.m
//  TerritoryShopkeeper
//
//  Created by 李小龙 on 2017/11/30.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "MineTableViewCell.h"

@implementation MineTableViewCell

+ (instancetype)mineTableCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    NSString *identifier;
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
        {
            index = 0;
            identifier = @"mineTableFirst";
        } break;
        case 1:
        {
            index = 1;
            identifier = @"mineTableSecond";
        } break;
        default:
            break;
    }
    MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MineTableViewCell" owner:self options:nil] objectAtIndex:index];
    }
    return cell;
}
- (void)updateSecondCellWith:(NSMutableArray *)arr indexPath:(NSIndexPath *)indexPath {
    CGFloat buttonW = ScreenWidth/4.0;
    CGFloat buttonH = self.height;
    for (LXLTopIconBottomTitleButton *button in self.contentView.subviews) {
        if ([button isKindOfClass:[LXLTopIconBottomTitleButton class]]) {
            [button removeFromSuperview];
        }
    }
    for (NSInteger i = 0; i < 4; i++) {
        if (indexPath.row*4+i < arr.count) {
            NSDictionary *dic = arr[indexPath.row*4+i];
            
            LXLTopIconBottomTitleButton *button = [LXLTopIconBottomTitleButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:CGRectMake(i*buttonW, 0, buttonW, buttonH)];
            [button setTitleColor:[UIColor blackTextColor] forState:UIControlStateNormal];
            [button.titleLabel setFont:TextPingFangFontSize(12)];
            [button setTitle:dic[@"title"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:dic[@"image"]] forState:UIControlStateNormal];
            if ([dic[@"isshow"] boolValue]) {
                [button.redPoint setHidden:NO];
            } else {
                [button.redPoint setHidden:YES];
            }
            [button setTag:indexPath.row*4+i+1];
            [button addTarget:self action:@selector(secondCellButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            
            [self.contentView addSubview:button];
        }
    }
    if (arr.count < (indexPath.row+1)*4) {
        [self.secondLineView setHidden:YES];
    } else {
        [self.secondLineView setHidden:NO];
    }
}

- (IBAction)couponsButtonAction:(id)sender {
    if (self.block) {
        self.block(ClickTypeCoupons);
    }
}

- (void)secondCellButtonAction:(id)sender {
    LXLTopIconBottomTitleButton *button = (LXLTopIconBottomTitleButton *)sender;
    if (self.block) {
        self.block(button.tag);
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
